﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint;

namespace SharePointees.EnhancedLookupField.Controls
{
    public class ELFListFieldIterator : ListFieldIterator
    {
        protected override void CreateChildControls()
        {
            this.Controls.Clear();
            if (this.ControlTemplate == null)
            {
                throw new ArgumentException("Could not find ListFieldIterator control template.");
            }
            for (int i = 0; i < base.Fields.Count; i++)
            {
                SPField field = base.Fields[i];
                if (!this.IsFieldExcluded(field))
                {
                    CompositeField child = new CompositeField();

                    if (field.Type == SPFieldType.Lookup)
                        child.TemplateName = "EnhancedLookupField";
                    else
                        child.TemplateName = "CustomCompositeField";

                    child.ControlMode = base.ControlMode;
                    child.FieldName = field.InternalName;
                    this.Controls.Add(child);

                }
            }
        }
    }
}
